package com.qfedu.service.impl;

import com.qfedu.dao.GoodsClassifyRepository;
import com.qfedu.pojo.entity.GoodsClassify;
import com.qfedu.pojo.req.GoodsClassifyReq;
import com.qfedu.pojo.resp.BaseResp;
import com.qfedu.service.GoodsClassifyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName GoodsclassifyServiceImpl
 * @Description TODO
 * @Author young
 * @Date 2022-09-27 14:20
 * @Version 1.0
 **/
@Service
public class GoodsClassifyServiceImpl implements GoodsClassifyService {

    @Autowired
    GoodsClassifyRepository goodsclassifyRepository;

    @Override
    public BaseResp findAll() {
        List<GoodsClassify> all = goodsclassifyRepository.findAll();
        return new BaseResp(1,"success",all,null);
    }

    @Override
    public BaseResp saveOrUpdate(GoodsClassifyReq goodsClassifyReq) {
        GoodsClassify goodsClassify = new GoodsClassify();
        BeanUtils.copyProperties(goodsClassifyReq,goodsClassify);
        goodsclassifyRepository.saveAndFlush(goodsClassify);
        return new BaseResp().Success();
    }

    @Override
    public BaseResp deleteById(GoodsClassifyReq goodsClassifyReq) {
        goodsclassifyRepository.deleteById(goodsClassifyReq.getGoodsClassifyId());
        return new BaseResp().Success();
    }
}
